package cn.brilliantfuture.commentry.profile;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 
 * Title: Communication Entry
 * 
 * Author: LiTian
 * 
 * Date: 2011-10-25
 * 
 * Description:
 * 
 */
public abstract class DefaultProfile {
	private static Logger logger = Logger.getLogger(DefaultProfile.class.getName());
	private Properties properties = new Properties();

	/**
	 * 读取配置文件
	 * 
	 * @param profilePath
	 *            配置文件路径
	 * @throws IOException
	 * @throws FileNotFoundException
	 */
	protected void load(String profilePath) throws IOException, FileNotFoundException {
		if (profilePath == null || profilePath.trim().equals("")) {
			logger.error("load(String profilePath) : profilePath is illegal -> " + profilePath);
			throw new IOException();
		}

		FileInputStream fis = (FileInputStream) DefaultProfile.class.getResourceAsStream(profilePath);
		BufferedInputStream bis = new BufferedInputStream(fis);
		properties.load(bis);

		bis.close();
		fis.close();
	}

	/**
	 * 读取配置文件属性
	 * 
	 * @param key
	 *            键
	 * @return String
	 */
	public String get(String key) {
		return properties.getProperty(key);
	}

}
